package com.jeeplus.test.jlnu.teachingArchive.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.jeeplus.test.jlnu.teachingArchive.domain.entity.InsideInfo;
import com.jeeplus.test.jlnu.teachingArchive.domain.vo.InsideInfoVo;
import com.jeeplus.test.jlnu.teachingArchive.service.InsideInfoService;
import com.jeeplus.test.tools.resp.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@Slf4j
@RestController
@RequestMapping(value = "/test/inside")
public class InsideInfoController {
    @Autowired
    private InsideInfoService insideInfoService;

    @PostMapping("/compose")
    public R saveAndLink(@RequestBody InsideInfoVo insideInfoVo) {
        return insideInfoService.saveAndLinkAcademic(insideInfoVo);
    }
    @GetMapping("/detail/{id}")
    public R getInsideDetail(@PathVariable String id) {
        InsideInfoVo detailVo = insideInfoService.getDetailById(id);
        return R.suc(detailVo);
    }
    @PostMapping("/saveOrUpdate")
    public InsideInfoVo saveOrUpdate(@RequestBody InsideInfoVo insideInfoVo) {
        return insideInfoService.saveOrUpdate(insideInfoVo);
    }
    @GetMapping("/page")
    public IPage<InsideInfoVo> page(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            InsideInfo query) {
        Page<InsideInfo> page = new Page<>(pageNum, pageSize);
        return insideInfoService.page(page, query);
    }
    @DeleteMapping("/delete")
    public ResponseEntity<String> delete(@RequestParam(required = false) String ids) {
        if (ids == null || ids.trim().isEmpty()) {
            return ResponseEntity.badRequest().body("400: ids参数不能为空");
        }
        String[] idArray = ids.split(",");
        if (idArray.length == 0) {
            return ResponseEntity.badRequest().body("400: 未找到有效ID");
        }
        insideInfoService.removeByIds(Lists.newArrayList(idArray));
        return ResponseEntity.ok("200");
    }


}
